from research.calcor import calcor_base

class updown(calcor_base):
    def __init__(self,timeperiod=2):
        super().__init__(timeperiod=timeperiod,datatype="dim1")
        self.fx=None
    def calc(self):
        """
        Args:
            b:曲线向上1，向下-1,拐点  2，-2

        Returns:

        """
        b=self.hisdata[-1]
        preb=self.hisdata[0]
        if self.fx is None:
            if preb<b:
                self.fx=1
            else:
                self.fx=-1
        elif self.fx>=1:
            if b<preb:
                self.fx=-2
            else:
                self.fx = 1
        elif self.fx<=-1:
            if b>preb:
                self.fx=2
            else:
                self.fx=-1
        return self.fx